﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//反射
namespace HelpAttribute {
    using System;

    //自定义一个 Attribute ，范围是所有
    [AttributeUsage(AttributeTargets.All)]
    public class HelpAttribute : System.Attribute {
        public readonly string Url;

        public string Topic  // Topic 是一个命名（named）参数
        {
            get {
                return topic;
            }
            set {

                topic = value;
            }
        }

        public HelpAttribute(string url)  // url 是一个定位（positional）参数
        {
            this.Url = url;
        }

        private string topic;
    }
    //使用自定义的Attribute 
    [HelpAttribute("Information on the class MyClass")]
    class MyClass {
        private string name;
        private string Testse() {
            return "123";
                }
    }

    namespace AttributeAppl {
        class Program {
            static void Main(string[] args) {
                System.Reflection.MemberInfo info = typeof(MyClass);
                //返回自定义注解的属性
                object[] attributes = info.GetCustomAttributes(true);
                foreach (var item in attributes)
                for (int i = 0; i < attributes.Length; i++) {
                    System.Console.WriteLine(attributes[i]);
                }
                Console.ReadKey();

            }
        }
    }
}
